package com.example.bookstore.beans;

import java.util.List;

import javax.faces.bean.ManagedBean;

import com.example.bookstore.entity.Book;
import com.example.bookstore.exception.BooksNotFoundException;

@ManagedBean(name = "catalog")
public class CatalogBean extends BaseBean {
	public List<Book> books() throws BooksNotFoundException {
		return bookController().getBooks();
	}

	@Override
	public String clear() {
		shoppingCart().clear();
		return "catalog";
	}

	public String add() {
		shoppingCart().add(selected().getBookId(), selected());
		return "catalog";
	}

	@Override
	public String checkout() {
		return "checkout";
	}

	public int getTotalBooks() {
		return shoppingCart().getNumberOfItems();
	}
}
